// pages/hire/hire.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hireInfo: {},
    settlementMethod: ['日结', '周结', '月结'],
    startTime: [
      ['01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00',
        '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '24:00',
      ],
      ['01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00',
        '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '24:00',
      ]
    ],
    workTimeIndex: [0, 0],
    startDate: [
      ['周一', '周二', '周三', '周四', '周五', '周六', '周天'],
      ['周一', '周二', '周三', '周四', '周五', '周六', '周天']
    ],
    workDateIndex: [0, 0],
  },

  // 选择结算方式
  chooseSettlemen: function (e) {
    this.setData({
      settlemenIndex: e.target.dataset.index
    })
  },

  // 上班时间
  bindTimeChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      workTimeIndex: e.detail.value
    })
  },

  bindTimeColumnChange: function (e) {
    console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
  },

  // 上班日期
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      workDateIndex: e.detail.value
    })
  },

  bindDateColumnChange: function (e) {
    console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
  },

  // 发起雇佣
  workHire: function () {
    app.post('Work/contract', {
      id: this.data.hireInfo.c_id
    }).then(res => {
      if (res.data.result_code == 99) {
        wx.requestPayment({
          timeStamp: res.data.result_data.timeStamp,
          nonceStr: res.data.result_data.nonceStr,
          package: res.data.result_data.package,
          signType: 'MD5',
          paySign: res.data.result_data.paySign,
          success(res) {
            wx.showModal({
              title: '提示',
              content: '雇佣成功,请等待对方确认',
              showCancel: false,
              success: res => {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '/pages/myHire/myHire',
                  })
                }
              }
            })
          },
          fail(res) {}
        })
      } else {

      }
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    app.post('Work/hire', {
      workId: options.workId,
      resumeId: options.resumeId
    }).then(res => {
      that.setData({
        hireInfo: res.data.result_data
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})